package com.ttsx.controller;

import com.ttsx.pojo.dto.user.UserLoginDTO;
import com.ttsx.pojo.dto.user.UserQueryDTO;
import com.ttsx.pojo.dto.user.UserRegisterDTO;
import com.ttsx.service.UserService;
import com.ttsx.core.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wb
 * @since 2025-03-01
 */

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    public Result<?> login(@RequestBody UserLoginDTO userLoginDTO) {
        return Result.success(userService.login(userLoginDTO));
    }


    @PostMapping("register")
    public Result<?> register(@RequestBody UserRegisterDTO userRegisterDTO) {
        return Result.success(userService.register(userRegisterDTO));
    }

    @GetMapping("logout")
    public Result<?> logout() {
        userService.logout();
        return Result.success();
    }

    @PostMapping("page/{pIndex}/{pSize}")
    public Result<?> pageUser(
            @PathVariable("pIndex") Integer pIndex,
            @PathVariable("pSize") Integer pSize,
            @RequestBody UserQueryDTO userQueryDTO) {
        return Result.success(userService.getPage(pIndex, pSize, userQueryDTO));
    }

}
